<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/23 0023
 * Time: 16:43
 */

namespace app\common\traits;

use app\admin\logic\Origin;
use app\admin\logic\Banji;
use app\admin\logic\State;
use app\admin\controller\User;
use app\api\controller\Client;

trait Common
{

    private static $common; //服务层对象
    /**
     * 获取公共的逻辑层
     * @return \app\admin\logic\Common
     * @author: Huang
     */
    static protected function getCommonModel()
    {
        if (is_null(self::$common) || !isset (self::$common)) {
            self::$common = new \app\admin\logic\Common();
        }
        return self::$common;
    }

    /**
     * 订单数据校验
     * @param $data
     * @return mixed
     * @internal
     */
    public static function Verification($data)
    {
//        dump($data);
        //ID
        if (!empty($data['id'])) {
            $map['id'] = $data['id'];
        }
        //添加客资的类型
        if (!empty($data['addtype'])) {
            $map['addtype'] = $data['addtype'];
        }
        //主顾客姓名
        if (!empty($data['name_z'])) {
            $map['name_z'] = $data['name_z'];
        }
        //备顾客姓名
        if (!empty($data['name_f'])) {
            $map['name_f'] = $data['name_f'];
        }
        //宝宝姓名
        if (!empty($data['bbname'])) {
            $map['bbname'] = $data['bbname'];
        }
        //主要联系电话
        if (!empty($data['phone_z'])) {
            $map['phone_z'] = $data['phone_z'];
        }
        //备注联系电话
        if (!empty($data['phone_f'])) {
            $map['phone_f'] = $data['phone_f'];
        }
        //主要顾客性别
        if (!empty($data['gender_z']) || $data['gender_z'] == '0') {
            $map['gender_z'] = $data['gender_z'];
        }
        //备顾客性别
        if (!empty($data['gender_f']) || $data['gender_f'] == '0') {
            $map['gender_f'] = $data['gender_f'];
        }
        //宝宝性别
        if (!empty($data['gender_b']) || $data['gender_b'] == '0') {
            $map['gender_b'] = $data['gender_b'];
        }
        //宝宝年龄
        if (!empty($data['bbage'])) {
            $map['bbage'] = $data['bbage'];
        }
        //微信
        if (!empty($data['wechat'])) {
            $map['wechat'] = trim($data['wechat']);
        }
        //QQ
        if (!empty($data['qq'])) {
            $map['qq'] = trim($data['qq']);
        }
        //渠道
        if (!empty($data['channel'])) {
            $map['channel'] = $data['channel'];
        }
        //来源
        if (!empty($data['source']) || $data['source'] == '0') {
            $map['source'] = $data['source'];
        }
        //班级
        if (!empty($data['banji']) || $data['banji'] == '0') {

            if ((int)$data['banji']==0){
                $banji = new Banji();
                $banjiarr = $banji->getModel()->where('banjiname',$data['banji'])->field('id')->find();
                $map['banji'] = $banjiarr['id'];
            }else{
                $map['banji'] = $data['banji'];
            }

        }
        //上课时间
        if (!empty($data['xingqi'])) {
            $map['xingqi'] = $data['xingqi'];
        }

        //上课时间段
        if (!empty($data['shijianduan'])) {
            $shijian = explode('-',$data['shijianduan']);
            $shijian1 = array();
            foreach ($shijian as $v){
                $shijian1 [] = explode(':',trim($v));
            }

            foreach ($shijian1 as $k=>$v){
                foreach ($v as $ka=>$va)
                {
                    unset($shijian1[$k][2]);
                }
                $shijian1[$k] =implode(':',$shijian1[$k]);
            }

            $map['shijianduan'] = implode('-',$shijian1);

        }

        //拍摄方式
        if (!empty($data['shotmode'])) {
            $map['shotmode'] = $data['shotmode'];
        }
        //是否加急
        if (!empty($data['urgent'])) {
            $map['urgent'] = $data['urgent'];
        }
        //拍摄类别
        if (!empty($data['leibie'])) {
            $map['leibie'] = $data['leibie'];
        }
        //区域
        if (!empty($data['diqu'])) {
            $map['diqu'] = $data['diqu'];
        }
        //活动
        if (!empty($data['activity'])) {
            $map['activity'] = $data['activity'];
        }
        //预算金额
        if (!empty($data['budget'])) {
            $map['budget'] = $data['budget'];
        }
        //意向度
        if (!empty($data['intention'])) {
            $map['intention'] = $data['intention'];
        }
        //预计拍摄时间
        if (!empty($data['shot_time'])) {
            $map['shot_time'] = $data['shot_time'];
        }
        //收集日期
        if (!empty($data['sjtime'])) {
            $map['sjtime'] = strtotime($data['sjtime']);
        }
        //预约进店时间
        if (!empty($data['yyjdtime'])) {
            $map['yyjdtime'] = strtotime($data['yyjdtime']);
        }
        //预约拍摄时间
        if (!empty($data['yypstime'])) {
            $map['yypstime'] = strtotime($data['yypstime']);
        }
        //追踪时间
        if (!empty($data['zztime'])) {
            $map['zztime'] = strtotime($data['zztime']);
        }
        //选片时间
        if (!empty($data['xptime'])) {
            $map['xptime'] = strtotime($data['xptime']);
        }
        //下次拍摄时间
        if (!empty($data['xcpstime'])) {
            $map['xcpstime'] = strtotime($data['xcpstime']);
        }
        //宝宝出生日期
        if (!empty($data['bbcstime'])) {
            if(is_string($data['bbcstime'])){
                $map['bbcstime'] = strtotime($data['bbcstime']);
            }else{
                $map['bbcstime'] = $data['bbcstime'];
            }
        }
        //预产期
        if (!empty($data['yctime'])) {
            $map['yctime'] = strtotime($data['yctime']);
        }
        //建单部门
        if (!empty($data['jd_depar'])) {
            $map['jd_depar'] = $data['jd_depar'];
        }
        //建单客服
        if (!empty($data['jdry'])) {
            $map['jdry'] = $data['jdry'];
        }
        //邀约部门
        if (!empty($data['yykf_depart'])) {
            $map['yykf_depart'] = $data['yykf_depart'];
        }
        //邀约组
        if (!empty($data['yykf_group'])) {
            $map['yykf_group'] = $data['yykf_group'];
        }
        //邀约客服
        if (!empty($data['yykf'])) {
            $map['yykf'] = $data['yykf'];
        }
        //订单状态
        if (!empty($data['state'])) {
            $map['state'] = $data['state'];
        }
        //门店
        if (!empty($data['mendian'])) {
            $map['mendian'] = $data['mendian'];
        }
        //门市
        if (!empty($data['menshi']) || $data['menshi'] == '0') {
            $map['menshi'] = $data['menshi'];
        }
        //摄影师
        if (!empty($data['photo_grapher']) || $data['photo_grapher'] == '0') {
            $map['photo_grapher'] = $data['photo_grapher'];
        }
        //预约拍摄地址
        if (!empty($data['waipai_address'])) {
            $map['waipai_address'] = $data['waipai_address'];
        }
        //下次追踪原因
        if (!empty($data['track'])) {
            $map['track'] = $data['track'];
        }
        //未到流失原因
        if (!empty($data['nostore'])) {
            $map['nostore'] = $data['nostore'];
        }
        //无需跟踪原因
        if (!empty($data['tracking'])) {
            $map['tracking'] = $data['tracking'];
        }
        //到店流失原因
        if (!empty($data['instoreyy'])) {
            $map['instoreyy'] = $data['instoreyy'];
        }
        //支付方式
        if(!empty($data['payment'])){
            $map['payment'] = $data['payment'];
        }
        //支付订单编号
        if(!empty($data['pay_order'])){
            $map['pay_order'] = $data['pay_order'];
        }
        //验证码
        if (!empty($data['code'])) {
            $map['code'] = $data['code'];
        }
        //拍摄方式
        if (!empty($data['shot_mode'])) {
            $map['shot_mode'] = $data['shot_mode'];
        }
        //套系金额
        if (!empty($data['txje'])) {
            $map['txje'] = $data['txje'];
        }
        //实收金额
        if (!empty($data['ssje'])) {
            $map['ssje'] = $data['ssje'];
        }
        //应收金额
        if (!empty($data['ysje'])) {
            $map['ysje'] = $data['ysje'];
        }
        //后期金额
        if (!empty($data['hqje'])) {
            $map['hqje'] = $data['hqje'];
        }
        //邀约备注
        if (!empty($data['yybz'])) {
            $map['yybz'] = $data['yybz'];
        }
        //渠道备注
        if (!empty($data['qdbz'])) {
            $map['qdbz'] = $data['qdbz'];
        }
        //门市备注
        if (!empty($data['msbz'])) {
            $map['msbz'] = $data['msbz'];
        }
        //拍摄备注
        if (!empty($data['psbz'])) {
            $map['psbz'] = $data['psbz'];
        }
        //添加顾客微信状态
        if (!empty($data['jwxtype']) || $data['jwxtype'] == '0') {
            $map['jwxtype'] = $data['jwxtype'];
        }
        //报名状态
        if (!empty($data['signup_type'])) {
            $map['signup_type'] = $data['signup_type'];
        }
        //报名费用
        if (!empty($data['signup_cost'])) {
            $map['signup_cost'] = $data['signup_cost'];
        }
        //班级备注
//        if (!empty($data['banji'])) {
//            $map['banji'] = $data['banji'];
//        }
//        //星期备注
//        if (!empty($data['xingqi'])) {
//            $map['xingqi'] = $data['xingqi'];
//        }
//        //时间段备注
//        if (!empty($data['shijianduan'])) {
//            $map['shijianduan'] = $data['shijianduan'];
//        }

        return $map;
    }


    /**
     * 邀约数据校验
     * @param $data
     * @return mixed
     * @author: Huang
     * @internal
     */
    protected function invitCheck($data)
    {
        if (!empty($data['id'])) {
            $map['order_id'] = $data['id'];                         // 订单编号
        }
        if (!empty($data['reason'])) {
            $map['reason'] = $data['reason'];                       // 邀约结果原因
        }
        if (!empty($data['diqu'])) {
            $map['diqu'] = $data['diqu'];                           // 地区
        }
        if (!empty($data['zztime'])) {
            $map['zztime'] = $data['zztime'];                    // 下次追踪时间
        }
        if (!empty($data['yyjdtime'])) {
            $map['yyjdtime'] = $data['yyjdtime'];                   // 预约到店时间
        }
        if (!empty($data['yypstime'])) {
            $map['yypstime'] = $data['yypstime'];                   // 预计拍照时间
        }
        if (!empty($data['shot_range'])) {
            $map['shot_range'] = $data['shot_range'];               // 预计拍照时间范围
        }
        if (!empty($data['xptime'])) {
            $map['xptime'] = $data['xptime'];                       //选片时间
        }
        if (!empty($data['xcpstime'])) {
            $map['xcpstime'] = $data['xcpstime'];                   //下次拍摄时间
        }
        if (!empty($data['waipai_address'])) {
            $map['waipai_address'] = $data['waipai_address'];       //预约拍摄地址
        }
        if (!empty($data['state'])) {
            $map['state'] = $data['state'];                         // 订单状态
        }
        if (!empty($data['mendian'])) {
            $map['mendian'] = $data['mendian'];                     // 门店
        }
        if (!empty($data['photo_grapher'])) {
            $map['photo_grapher'] = $data['photo_grapher'];         //摄影师
        }
        if (!empty($data['yybz'])) {
            $map['yybz'] = $data['yybz'];                           // 邀约备注
        }
        if (!empty($data['nostore'])) {
            $map['nostore'] = $data['nostore'];                     // 未到流失原因
        }
        if (!empty($data['track'])) {
            $map['track'] = $data['track'];                         // 下次跟踪原因
        }
        if (!empty($data['tracking'])) {
            $map['tracking'] = $data['tracking'];                   // 无需跟踪原因
        }
        if (!empty($data['instoreyy'])) {
            $map['instoreyy'] = $data['instoreyy'];                 // 到店流失原因
        }
        if (!empty($data['fish'])) {
            $map['fish'] = $data['fish'];                           // 到店流失原因
        }
        if (!empty($data['invalid'])) {
            $map['invalid'] = $data['invalid'];                     // 无效原因
        }
        if (!empty($data['rinvalid'])) {
            $map['rinvalid'] = $data['rinvalid'];                    // 返无效原因
        }
        if (!empty($data['payment'])) {
            $map['payment'] = $data['payment'];                       // 支付方式
        }
        if (!empty($data['code'])) {
            $map['code'] = $data['code'];                             // 验证码
        }
        if (!empty($data['pay_order'])) {
            $map['pay_order'] = $data['pay_order'];                   // 支付订单编号
        }
        if (!empty($data['budget'])) {
            $map['budget'] = $data['budget'];                         // 预算金额
        }
        if (!empty($data['paid'])) {
            $map['paid'] = $data['paid'];                           // 已付金额
        }
        if (!empty($data['txje'])) {
            $map['txje'] = $data['txje'];                         // 套系金额
        }
        if (!empty($data['ysje'])) {
            $map['ysje'] = $data['ysje'];                         // 应收金额
        }
        if (!empty($data['ssje'])) {
            $map['ssje'] = $data['ssje'];                         // 实收金额
        }
        if (!empty($data['hqje'])) {
            $map['hqje'] = $data['hqje'];                           //后期金额
        }

        return $map;
    }

    /**
     * 门店数据校验
     * @param $data
     * @return mixed
     * @author: Huang
     * @internal
     */
    protected function storeCheck($data)
    {
        if (!empty($data['id'])) {
            $map['order_id'] = $data['id'];                         // 订单编号
        }
        if (!empty($data['mendian'])) {
            $map['mendian'] = $data['mendian'];                     // 门店
        }
        if (!empty($data['state'])) {
            $map['state'] = $data['state'];                         // 订单状态
        }
        if (!empty($data['menshi'])) {
            $map['menshi'] = $data['menshi'];                       // 门市
        }
        if (!empty($data['photo_grapher'])) {
            $map['photo_grapher'] = $data['photo_grapher'];         //摄影师
        }
        if (!empty($data['ddtime'])) {
            $map['ddtime'] = strtotime($data['ddtime']);            // 到店时间
        }
        if (!empty($data['shot_range'])) {
            $map['shot_range'] = $data['shot_range'];               // 预计拍照时间范围
        }
        if (!empty($data['yypstime'])) {
            $map['yypstime'] = $data['yypstime'];                   // 预计拍照时间
        }
        if (!empty($data['xptime'])) {
            $map['xptime'] = $data['xptime'];                       //选片时间
        }
        if (!empty($data['xcpstime'])) {
            $map['xcpstime'] = $data['xcpstime'];                   //下次拍摄时间
        }
        if (!empty($data['txje'])) {
            $map['txje'] = $data['txje'];                           // 套系金额
        }
        if (!empty($data['ysje'])) {
            $map['ysje'] = $data['ysje'];                           // 应收金额
        }
        if (!empty($data['ssje'])) {
            $map['ssje'] = $data['ssje'];                           // 实收金额
        }
        if (!empty($data['hqje'])) {
            $map['hqje'] = $data['hqje'];                           //后期金额
        }
        if (!empty($data['msbz'])) {
            $map['msbz'] = $data['msbz'];                           // 门市备注
        }
        if (!empty($data['nostore'])) {
            $map['nostore'] = $data['nostore'];                     // 未到流失原因
        }
        if (!empty($data['track'])) {
            $map['track'] = $data['track'];                         // 下次跟踪原因
        }
        if (!empty($data['tracking'])) {
            $map['tracking'] = $data['tracking'];                   // 无需跟踪原因
        }
        if (!empty($data['instoreyy'])) {
            $map['instoreyy'] = $data['instoreyy'];                 // 到店流失原因
        }
        if (!empty($data['payment'])) {
            $map['payment'] = $data['payment'];                     // 支付方式
        }
        if (!empty($data['code'])) {
            $map['code'] = $data['code'];                           // 验证码
        }
        if (!empty($data['pay_order'])) {
            $map['pay_order'] = $data['pay_order'];                 // 支付订单编号
        }
        if (!empty($data['budget'])) {
            $map['budget'] = $data['budget'];                       // 预算金额
        }
        if (!empty($data['paid'])) {
            $map['paid'] = $data['paid'];                           // 已付金额
        }
        return $map;
    }


    /**
     * 查询排除空字段数据
     * @param $data
     * @return mixed
     * @internal
     */
    public function checkData($data)
    {
        // ID/姓名/电话
        if (!empty($data['only'])) {
            $map['id|name_z|name_f|phone_z|phone_f'] = ['like', $data['only']];
        }
        //ID
        if (!empty($data['id'])) {
            trim($data['id']);
            $map['id'] = ['eq', $data['id']];
        }
        // 顾客姓名
        if (!empty($data['name_z'])) {
            $map['name_z|name_f'] = ['like', $data['name_z']];
        }
        //宝宝姓名
        if (!empty($data['bbname'])) {
            trim($data['bbname']);
            $map['bbname'] = ['eq', $data['bbname']];
        }
        //主要联系电话
        if (!empty($data['phone_z'])) {
            trim($data['phone_z']);
            $map['phone_z'] = ['eq', $data['phone_z']];
        }
        //备注联系电话
        if (!empty($data['phone_f'])) {
            trim($data['phone_f']);
            $map['phone_f'] = ['eq', $data['phone_f']];
        }
        //微信
        if (!empty($data['wechat'])) {
            trim($data['wechat']);
            $map['wechat'] = ['eq', $data['wechat']];
        }
        //QQ
        if (!empty($data['qq'])) {
            trim($data['qq']);
            $map['qq'] = ['eq', $data['qq']];
        }
        //渠道
        if (!empty($data['channel'])) {
            $data['channel'] = explode(",", $data['channel']);
            if (is_array($data['channel'])) {
                $map['channel'] = ['in', $data['channel']];
            } else {
                $map['channel'] = ['eq', $data['channel']];
            }
        }
        //来源
        if (!empty($data['source'])) {
            $data['source'] = explode(",", $data['source']);
            if (is_array($data['source'])) {
                $map['source'] = ['in', $data['source']];
            } else {
                $map['source'] = ['eq', $data['source']];
            }
        }
        //班级
        if (!empty($data['banji'])){
            $data['banji'] = explode(',',$data['banji']);
            if (is_array($data['banji'])){
                $map['banji'] = ['in',$data['banji']];
            }else{
                $map['banji'] = ['eq' ,$data['banji']];
            }
        }
        if (!empty($data['xingqi'])){
            $data['xingqi'] = explode(',',$data['xingqi']);
            if (is_array($data['xingqi'])){
                $map['xingqi'] = ['in',$data['xingqi']];
            }else{
                $map['xingqi'] = ['eq',$data['xingqi']];
            }
        }
        // 是否加急
        if (!empty($data['urgent'])) {
            $map['urgent'] = ['eq', $data['urgent']];
        }
        //订单类别
        if (!empty($data['leibie'])) {
            $data['leibie'] = explode(",", $data['leibie']);
            if (is_array($data['leibie'])) {
                $map['leibie'] = ['in', $data['leibie']];
            } else {
                $map['leibie'] = ['eq', $data['leibie']];
            }
        }
        //区域
        if (!empty($data['diqu'])) {
            $data['diqu'] = explode(",", $data['diqu']);
            if (is_array($data['diqu'])) {
                $map['diqu'] = ['in', $data['diqu']];
            } else {
                $map['diqu'] = ['eq', $data['diqu']];
            }
        }
        //活动
        if (!empty($data['activity'])) {
            $map['activity'] = ['eq', $data['activity']];
        }
        //建单部门
        if (!empty($data['jd_depar'])) {
            $map['jd_depar'] = ['eq', $data['jd_depar']];
        }
        //建单人员
        if (!empty($data['jdry'])) {
            $data['jdry'] = explode(",", $data['jdry']);
            if (is_array($data['jdry'])) {
                $map['jdry'] = ['in', $data['jdry']];
            } else {
                $map['jdry'] = ['eq', $data['jdry']];
            }
        }
        //邀约组
        if (!empty($data['yykf_group'])) {
            $data['yykf_group'] = explode(",", $data['yykf_group']);
            if (is_array($data['yykf_group'])) {
                $map['yykf_group'] = ['in', $data['yykf_group']];
            } else {
                $map['yykf_group'] = ['eq', $data['yykf_group']];
            }
        }
        //邀约客服
        if (!empty($data['yykf'])) {
            $data['yykf'] = explode(",", $data['yykf']);
            if (is_array($data['yykf'])) {
                $map['yykf'] = ['in', $data['yykf']];
            } else {
                $map['yykf'] = ['eq', $data['yykf']];
            }
        }
        //订单状态
        if (!empty($data['state'])) {
            $data['state'] = explode(",", $data['state']);
            if (is_array($data['state'])) {
                $map['state'] = ['in', $data['state']];
            } else {
                $map['state'] = ['eq', $data['state']];
            }
        }
        //拍摄方式
        if (!empty($data['shot_mode'])) {
            $data['shot_mode'] = explode(",", $data['shot_mode']);
            if (is_array($data['shot_mode'])) {
                $map['shot_mode'] = ['in', $data['shot_mode']];
            } else {
                $map['shot_mode'] = ['eq', $data['shot_mode']];
            }
        }
        if (!empty($data['state_k'])) {
            $data['state'] = explode(",", $data['state_k']);
            if (is_array($data['state'])) {
                $map['state'] = ['in', $data['state_k']];
            } else {
                $map['state'] = ['eq', $data['state_k']];
            }
        }
        //门店
        if (!empty($data['mendian'])) {
            $data['mendian'] = explode(",", $data['mendian']);
            if (is_array($data['mendian'])) {
                $map['mendian'] = ['in', $data['mendian']];
            } else {
                $map['mendian'] = ['eq', $data['mendian']];
            }
        }
        //门市
        if (!empty($data['menshi'])) {
            $data['menshi'] = explode(",", $data['menshi']);
            if (is_array($data['menshi'])) {
                $map['menshi'] = ['in', $data['menshi']];
            } else {
                $map['menshi'] = ['eq', $data['menshi']];
            }
        }
        //收集日期
        if (!empty($data['sjtime'])) {
            $sjtime = time_StrToArr($data['sjtime']);
            $map['sjtime'] = ['between time', $sjtime];
        }
        //宝宝出生日期
        if (!empty($data['bbcstime'])) {
            $bbcstime = time_StrToArr($data['bbcstime']);
            $map['bbcstime'] = ['between time', $bbcstime];
        }
        //预产期
        if (!empty($data['yctime'])) {
            $yctime = time_StrToArr($data['yctime']);
            $map['yctime'] = ['between time', $yctime];
        }
        //建单时间
        if (!empty($data['jdtime'])) {
            $jdtime = time_StrToArr($data['jdtime']);
            $map['jdtime'] = ['between time', $jdtime];
        }
        //追踪日期
        if (!empty($data['zztime'])) {
            $zztime = time_StrToArr($data['zztime']);
            $map['zztime'] = ['between time', $zztime];
        }
        //邀约分配时间
        if (!empty($data['yyfptime'])) {
            $yyfptime = time_StrToArr($data['yyfptime']);
            $map['yyfptime'] = ['between time', $yyfptime];
        }
        //门店分配时间
        if (!empty($data['mdfptime'])) {
            $mdfptime = time_StrToArr($data['mdfptime']);
            $map['mdfptime'] = ['between time', $mdfptime];
        }
        //门店领单时间
        if (!empty($data['mdldtime'])) {
            $mdldtime = time_StrToArr($data['mdldtime']);
            $map['mdldtime'] = ['between time', $mdldtime];
        }
        //邀约进店时间
        if (!empty($data['yytime'])) {
            $yytime = time_StrToArr($data['yytime']);
            $map['yytime'] = ['between time', $yytime];
        }
        //实际到店时间
        if (!empty($data['ddtime'])) {
            $ddtime = time_StrToArr($data['ddtime']);
            $map['ddtime'] = ['between time', $ddtime];
        }
        //流失时间
        if (!empty($data['lstime'])) {
            $lstime = time_StrToArr($data['lstime']);
            $map['lstime'] = ['between time', $lstime];
        }
        //未到店时间
        if (!empty($data['wddtime'])) {
            $wddtime = time_StrToArr($data['wddtime']);
            $map['wddtime'] = ['between time', $wddtime];
        }
        //未到流失时间
        if (!empty($data['yywdlstime'])) {
            $yywdlstime = time_StrToArr($data['yywdlstime']);
            $map['yywdlstime'] = ['between time', $yywdlstime];
        }
        //成交时间
        if (!empty($data['cjtime'])) {
            $cjtime = time_StrToArr($data['cjtime']);
            $map['cjtime'] = ['between time', $cjtime];
        }
        //无效时间
        if (!empty($data['wxtime'])) {
            $wxtime = time_StrToArr($data['wxtime']);
            $map['wxtime'] = ['between time', $wxtime];
        }
        //操作时间
        if (!empty($data['cztime'])) {
            $cztime = time_StrToArr($data['cztime']);
            $map['cztime'] = ['between time', $cztime];
        }


        /* 手机端 */
        //搜索ID或者手机号
        if (!empty($data['id_phonenum'])) {
            $map['id|phone_z|phone_f'] = ['eq', $data['id_phonenum']];
        }
        //今日追踪、
        $start = strtotime(date('Y-m-d 00:00:00'));
        $end = time();
        if ($data['today_xinxi'] == 'today_zhuizong' && empty($data['zztime'])) {
            $map['zztime'] = ['between time', [$start, $end]];
        }
        //今日联系
        if ($data['today_xinxi'] == 'today_lianxi' && empty($data['lxtime'])) {
            $map['lxtime'] = ['between time', [$start, $end]];
        }
        //今日成交
        if ($data['today_xinxi'] == 'today_chengjiao' && empty($data['cjtime'])) {//yysktime
            $map['cjtime'] = ['between time', [$start, $end]];
        }
        //今日流失
        if ($data['today_xinxi'] == 'today_liushi' && empty($data['lstime'])) {
            $map['lstime'] = ['between time', [$start, $end]];
        }
        //今日未到持续
        if ($data['today_xinxi'] == 'today_weidaochixu' && empty($data['wdcxtime'])) {
            $map['wdcxtime'] = ['between time', [$start, $end]];
        }
        //今日分配订单
        if ($data['today_xinxi'] == 'today_fenpei' && empty($data['yyfptime'])) {
            $map['yyfptime'] = ['between time', [$start, $end]];
        }
        //今日分配门店
        if ($data['today_xinxi'] == 'today_fenpeimendian' && empty($data['hsfptime'])) {
            $map['hsfptime'] = ['between time', [$start, $end]];
        }
        return $map;
    }

    /**
     * 业务查询校验
     * @param $data
     * @return mixed
     * @internal
     */
    public function queryData($data){
        // ID/姓名/电话
        if (!empty($data['only'])) {
            $data['only'] = trim($data['only']);
        }
        //微信
        if (!empty($data['wechat'])) {
            $data['wechat'] = trim($data['wechat']);
        }
        //QQ
        if (!empty($data['qq'])) {
            $data['qq'] = trim($data['qq']);
        }
        return $data;
    }

    /**
     * 获取相关数据
     * @internal
     */
    public function getDatas(){
        $common = self::getCommonModel();
        $allstate = new State();
        $allorigin = new Origin();
        $allbanji = new Banji();
        //渠道
        $channel = $common->getQudao();
        $this->assign('channel', $channel);
        //来源
        $source = $allorigin->getAllOrigins();
        $this->assign('source', $source);
        //班级
        $banji = $allbanji->getbanjiall();
        $this->assign('banji', $banji);
        //星期
        $xingqiarr = array(0=>'星期天',1=>'星期一',2=>'星期二',3=>'星期三',4=>'星期四',5=>'星期五',6=>'星期六');
        $this->assign('xingqi',$xingqiarr);
        //订单状态
        $state = $allstate->getAllStates();
//        dump($state);
        $this->assign('state',$state);
        $this->assign('json_state',\GuzzleHttp\json_encode($state));
        //获取子公司
        $sondepar = $common->getSonDepar(3);
        $this->assign('sondepar', $sondepar);
        //邀约组
        $yykf_group = $common->getSonDepar(3);
        if ($this->hasRole(['yyzg', 'yyzy'])) {
            $yykf_group = collect($yykf_group)->where('id', session('admin_user.depar_id'))->all();
        }
        $this->assign('yykf_group', $yykf_group);
        //邀约人员
        $yykf = $common->getUserByDeparId(3);
        if ($this->hasRole(['yyzg'])) {
            $yykf = $common->getUserByDeparId(session('admin_user.depar_id'));
        } elseif ($this->hasRole(['yyzy'])) {
            $yykf = collect($common->getUserByDeparId(session('admin_user.depar_id')))->where(id, session('admin_user.adminid'))->all();
        }
        $this->assign('yykf', $yykf);
        // 获取所有人员
        $userall = $common->getAllUserInfo()->all();
        $this->assign('userall', $userall);
        // 渠道组
        $jdry_group = $common->getSonDepar(1);
        if ($this->hasRole(['qdzg', 'qdzy'])) {
            $jdry_group = collect($jdry_group)->where('id', session('admin_user.depar_id'))->all();
        }
        $this->assign('jdry_group', $jdry_group);
        // 渠道人员
        $jdry = $common->getUserByDeparId(1);
        if ($this->hasRole(['qdzg'])) {
            $jdry = $common->getUserByDeparId(session('admin_user.depar_id'));
        } elseif ($this->hasRole(['qdzy', 'qdkf'])) {
            $jdry = $common->getUserByDeparId(session('admin_user.depar_id'));
        }
        $this->assign('jdry', $jdry);
        //意向
        $yixiang = $common->getIntention();
        $this->assign('yixiang', $yixiang);
        //预算
        $yusuan = $common->getBudget();
        $this->assign('yusuan', $yusuan);
        //类别
        $Leibie = $common->getLeibie();
        $this->assign('leibie', $Leibie);
        //活动
        $activity = $common->getAllActivity();
        $this->assign('activity', $activity);
        //区域
        $area = $common->getAllArea();
        $this->assign('area', $area);
        //支付方式
        $payment = $common->getPayment();
        $this->assign('payment', $payment);
        //门店
        $store = $common->getStore();
        $this->assign('mendian', $store);
        //门市
        $menshi = $common->getUserByDeparId(2);
        $this->assign('menshi', $menshi);
        //摄影师
        $photographer = $common->getUserByDeparId(6);
        $this->assign('photographer', $photographer);
        //获取反无效原因
        $invalid = $common->getInvalid();
        $this->assign('invalid', $invalid);
        //获取进店流失原因
        $instore = $common->getInstore();
        $this->assign('instoreyy', $instore);
        //获取无需追踪原因
        $tracking = $common->getTracking();
        $this->assign('tracking', $tracking);
        //获取下次追踪原因
        $track = $common->getTrack();
        $this->assign('track', $track);
        //未到店流失原因
        $nostore = $common->noStore();
        $this->assign('nostore', $nostore);
        //预计拍摄时间范围
        $stimate = $common->getStimate();
        $this->assign('stimate', $stimate);
        //意向拍摄次数
        $int_num = $common->getInt_num();
        $this->assign('int_num', $int_num);
        //拍摄方式
        $shotmode = $common->getShotMode();
        if ($this->hasRole(['qdzy', 'yyzy'])) {
            if ($this->hasRole('line')) {
            }else{
                $shotmode = array(collect($shotmode)->first());
            }
        }
        $this->assign('shotmode', $shotmode);
        //报名状态
        $signuptype = $common->getSignupType();
        $this->assign('signuptype', $signuptype);
    }

    /**
     * 订单状态统计
     *@internal
     */
    function getCountState(){
        $common = self::getCommonModel();
        //新客资
        $number1 = $common->getState(1);
        $this->assign('number1', $number1);
        //邀约进店
        $number3 = $common->getState(3);
        $this->assign('number3', $number3);
        //免费体验
        $number4 = $common->getState(4);
        $this->assign('number4', $number4);
        //无需追踪
        $number6 = $common->getState(6);
        $this->assign('number6', $number6);
        //无效
        $number10 = $common->getState(10);
        $this->assign('number10', $number10);
        //邀约店外拍
        $number21 = $common->getState(21);
        $this->assign('number21', $number21);
        //拍摄成功
        $number20 = $common->getState(20);
        $this->assign('number20', $number20);
    }

    /**
     * 加载页面权限检测区分
     * @param $name 请求URL地址
     * diction 权限
     * @return mixed
     * @author: wu
     */
    protected function loadpower($name)
    {
        $user = session('admin_user');
        if ($this->hasRole(['qdjl', 'qdzg', 'qdzy', 'qdkf'])) {
            if ($this->hasRole('qdjl')) {
                $this->assign('diction', 1);
            } elseif ($this->hasRole('qdzg')) {
                $this->assign('diction', 2);
            } elseif ($this->hasRole(['qdzy', 'qdkf'])) {
                $this->assign('diction', 3);
                if ($this->hasRole('line')) {
                    $this->assign('linezy', 4);
                }
                if($this->hasRole('unusual')){
                    $this->assign('unusual', 'true');
                }
            }
            $url = $name . '-qudao';
        } elseif ($this->hasRole(['yyjl', 'yyzg', 'yyzy'])) {
            if ($this->hasRole('yyjl')) {
                $this->assign('diction', 1);
                $this->assign('linezy', 4);
            } elseif ($this->hasRole('yyzg')) {
                $this->assign('diction', 2);
                $this->assign('linezy', 4);
            } elseif ($this->hasRole('yyzy')) {
                $this->assign('diction', 3);
                if ($this->hasRole('line')) {
                    $this->assign('linezy', 4);
                }
            }
            $url = $name . '-yaoyue';
        } elseif ($this->hasRole(['mdjl', 'mdzg', 'mdzy', 'diaodu', 'sheyingshi'])) {
            if ($this->hasRole('mdjl')) {
                $this->assign('diction', 1);
                $this->assign('diaodu', 4);
            } elseif ($this->hasRole('mdzg')) {
                $this->assign('diction', 2);
            } elseif ($this->hasRole('mdzy')) {
                $this->assign('diction', 3);
            } elseif ($this->hasRole('diaodu')) {
                $this->assign('diction', 2);
                $this->assign('diaodu', 4);
            } elseif ($this->hasRole('sheyingshi')){
                $this->assign('diction', 3);
                $this->assign('sys_photo', 5);
            }
            $url = $name . '-menshi';
        } else {
            $url = $name;
        }
        $users = new User();
        $user = session('admin_user.adminid');
        $common = self::getCommonModel();
        $user = collect($common->getAllUserInfo())->where('id' ,'eq' ,$user)->all();
        $user= collect($users->getDeparandPosition($user))->collapse()->all();
        $userimg = session('admin_user.avatar');
        session('weixinuser',$user);
        $this->assign('user', $user);
        session('userimg', $userimg);
        if(isMobile()){
            // $url = 'phone/home';
            $url = 'phone/'.$url ;
            $list = $common->getAuthByPid('131');
            // $time = Time::today();
            // $time = date('Y-m-d');
            $this->assign('lists', $list);
            return $this->fetch($url);
        }else{
            return $this->fetch($url);
        }
    }





}